﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DrawIO45.Models.Logic
{
    public static class LHelper
    {
        public static string GetTypeName(Type type)
        {
            if (type.IsGenericType)
            {
                var baseName = type.GetGenericTypeDefinition().Name.ToString();

                var fHeadName = baseName;
                var brIndex = fHeadName.LastIndexOf('`');
                if (brIndex != -1)
                    fHeadName = fHeadName.Substring(0, brIndex);

                var paramters = type.GetGenericArguments();

                return $"{fHeadName}<{(string.Join(", ", paramters.Select(n => GetTypeName(n))))}>";
            }

            return type.Name;
        }
    }
}
